<?php echo $this->HeadStyle()->captureStart() ?>
.col_style { background:#E1ECFF none repeat scroll 0 0; color:#778899; font-size:1.2em;padding:3px }
#main_body{float:left;}
#main_body tr {padding:3px; background:#fff}
#main_body table {background:#ccc}
#main_body p {margin:2px}
#judgetable {background:#fee;border: thin dotted #00FF00}
#all_semester{width:150px;margin:2px;float:right}
<?php echo $this->headStyle()->captureEnd() ?>
<?php echo $this->headScript()
->appendFile($this->js('plugins/jquery.template.js'))
->appendFile($this->js('plugins/jquery.form.js'))
->appendFile($this->js('plugins/jquery.blockUI.js'))
->captureStart()?>
var sdata = null;

var year_semester = '<?php echo $this->year_semester ?>';
var cyear = '<?php echo $this->sel_grade ?>';



$(document).ready(function(){
	//$().ajaxStop($.unblockUI);

	// 取資料
	getData();

	$("#period").change(function(){
		if ($("input:radio:checked").attr('id') == 'r2') {
			var p =$("#period").val();
			period_setup(p);
		}
	});


	$("#r2").click(function(){
		var p =$("#period").val();
		period_setup(p);
	});

	$("#jset_num").change(function(){
		judge_setup($(this).val());
	});
	$("#sel_grade").change(function(){
		cyear = $(this).val();
		$.blockUI({message:'<h1><?php echo $this->translate('Data reading ..')?></h1>',  border: '3px solid #f00'});
		getData();
		   setTimeout($.unblockUI, 1000);
	});
	$("#year_semester").change(function(){
		year_semester = $(this).val();
		$.blockUI({message:'<h1><?php echo $this->translate('Data reading ..')?></h1>',  border: '3px solid #f00'});
		getData();
		   setTimeout($.unblockUI, 1000);
	});

	var options = {
	    beforeSubmit: function(){
	     $('#main_body').block({message:'<h1><?php echo $this->translate('Performance data setting ..')?></h1>',  border: '3px solid #f00' });

	    },
        success: function(data){
       $('#main_body').unblock();

        }

	}

	$('#myform').ajaxForm(options);


});

	function getData(){
		var url = '<?php echo $this->baseScript ?>/getset/year_semester/'+year_semester+'/cyear/'+cyear;
		$.getJSON(url,
		function(data){
			sdata = data;
			initdata();
		});
	}

	function initdata() {
			var data = sdata;
			// 考次
			period_setup(data.period);
			// 等第
			judge_setup(data.judge_num);
			// 等第次數
			$("#jset_num").val(data.judge_num);
			$("#mode-1").val('');
			$("#mode-2").val('');
			$("#period").val(data.period);
			if (data.period_mode==1) {
				$("#r1").attr("checked",true);
				$("#mode-1").val(data.period_1[1]);
				$("#mode-2").val(data.period_1[2]);
			}
			else
				$("#r2").attr("checked",true);
	}

	function period_setup(p){
		$("#severally").empty();
		var t = $.template('<p id="${id}"><?php echo $this->translate('${times} accounts for periodic test')?> <input type="text" name="${name_1}" size="2" />%, <?php echo $this->translate('normal score for')?>  <input type="text" name="${name_2}" size="2" />%</p>');
		for(i=1;i <= p;i++) {
			$("#severally").append(t, {
				times: i,
				name_1 : 'm-1-'+i,
				name_2 : 'm-2-'+i,
				id     : 'sm-'+i
			});
	 	}

	   var ss = 0;
	   for(_obj in sdata.period_2 ) ss++;

	   for(i=1;i<=ss;i++) {
	 		$("#sm-"+i).children(":nth-child(1)").val(sdata.period_2[i][0]);
			$("#sm-"+i).children(":nth-child(2)").val(sdata.period_2[i][1]);
	 	}
	}


	function judge_setup(j){

		$("#judgetable").empty();
		var t = $.template('<p id="${id}"><input name="${js_name}" size="2"  /> <select name="${ps_name}" ><option value="&gt;">&gt;</option><option value="&gt;=">&gt;=</option><option value="=">=</option><option value="&lt;" >&lt;</option><option value="&lt;=" >&lt;=</option></select> <input type="text" name="${ns_name}" size="2"  /></p>');
		for(i=1;i <= j;i++) {
			$("#judgetable").append(t, {
				id		: 'j-'+i,
				js_name : 'js['+i+']',
				ps_name : 'ps['+i+']',
				ns_name : 'ns['+i+']'
			});
		}

		var ss = 0;
		for(_obj in sdata.judge) ss++;

		for(i=1;i<=ss;i++){
			$("#j-"+i).children(":nth-child(1)").val(sdata.judge[i][0]);
			$("#j-"+i).children(":nth-child(2)").val(sdata.judge[i][1]);
			$("#j-"+i).children(":nth-child(3)").val(sdata.judge[i][2]);
		}
	}

<?php echo $this->headScript()->captureEnd() ?>



<form action="<?php echo $this->baseScript?>/edit" method="post" id="myform" name="myform">
<div id="main_body">
<table>
	<tr style="background: #ffc">
		<td colspan="2">
		<div style="float:left">
		<?php echo $this->translate('current set')?> <select name="year_semester" id="year_semester">
		<?php echo  $this->YearSemesterOptions($this->year_semester)?>
		</select>	<select name="sel_grade" id="sel_grade">
		<?php echo $this->ClassGradeOptions()?>
		</select></div>
		<div style="float:right"><input type="submit" name="act" value="<?php echo $this->translate('save')?>" /></div>
		</td>
	</tr>
	<tr>
		<td class='col_style' colspan="2"><?php echo $this->translate('score configure')?></td>
	</tr>
	<tr>
		<td colspan="2"><?php echo $this->translate('current semester to examine the number of regular')?>：<select name="period" id="period">
		<?php for($i=0;$i<=10;$i++): ?>
			<option value="<?php echo $i ?>"><?php echo $i ?></option>
			<?php endfor; ?>
		</select> 次</td>
	</tr>
	<tr>
		<td class='col_style' colspan="2"><?php echo $this->translate('Distribution ratio of performance-related settings')?></td>
	</tr>
	<tr>
		<td  nowrap><label for="r1"><input type="radio" id="r1" name="mode" value="1"> <?php echo $this->translate('Each assessment the same proportion in both mining')?></label></td>
		<td nowrap>
		<p><?php echo $this->translate('the proportion of regular score')?>：<input type="text" name="mode-1" id="mode-1" size="3"
			value="" />%</p>

		<p><?php echo $this->translate('the proportion of normal score')?>：<input type="text" name="mode-2" id="mode-2" size="3"
			value="" />%</p>
		</td>
	</tr>

	<tr>
		<td nowrap><label for="r2"><input type="radio" id="r2" name="mode" value="2"> <?php echo $this->translate('Each take a different assessment ratio')?></label></td>
		<td id="severally" nowrap>

		</td>
	</tr>
	<tr>
		<td class='col_style' nowrap><?php echo $this->translate('Grade Setting')?>: <?php echo $this->translate('Grade Number')?>:
		<select name="jset_num" id="jset_num">
		<?for($i=1;$i<=10;$i++): ?>
		<option value="<?php echo $i ?>" ><?php echo $i ?></option>
		<?endfor; ?>
		</td>
		<td class='col_style' nowrap><?php echo $this->translate('copy configure')?></td>
	</tr>

	<tr>
		<td>
		<div id="judgetable"></div>
		</td>
		<td valign="top">
		<label id="all_name"><input type="checkbox" name="all_same" id="all_name" value="1"> <?php echo $this->translate('All levels use the same settings (which can be further modified by individual)')?></label>
		</td>
	</tr>
</table>
</div>
</form>
<div style="clear:both"></div>